<template>
	<u-popup :show="show" @close="show = false">
		<view style="padding: 32rpx;">
			<view class="page2">
				<view class="big-title">
					请选择您的行业类别
				</view>
				<view class="btm-title">
					<span style="color: #B81E1E;">*</span>行业类别可选择多个
				</view>
				<view class="select-wrap" v-for="(item,index) in hyList">
					<view class="select-label">
						{{item.hyflName}}
					</view>
					<view class="select-list">
						<view class="select-option" @click="selectAll(index)" :class="item.check?'active':''">
							选择全部
						</view>
						<view class="select-option" :class="type.check?'active':''"
							v-for="(type,typeIndex) in item.data" @click="selectType(index,typeIndex)">
							{{type.typeName}}
						</view>
					</view>
				</view>
				<u-button type="primary" shape="circle" text="确定" @click="submit()"></u-button>
			</view>
		</view>
	</u-popup>

</template>

<script>
	export default {
		name: 'hyflSelect',
		data() {
			return {
				show: false,
				navIndex: 0,
				hyList: [],
				type: ''


			};
		},
		onLoad(option) {},
		methods: {
			submit() {
				let list = [],
					listName = []
				for (let i = 0; i < this.hyList.length; i++) {
					for (let ii = 0; ii < this.hyList[i].data.length; ii++) {
						if (this.hyList[i].data[ii].check) {
							list.push(this.hyList[i].data[ii].id)
							listName.push(this.hyList[i].data[ii].typeName)
						}
					}
				}
				if (list.length === 0) {
					uni.showToast({
						title: "请至少选中一项行业分类",
						icon: "none"
					})
				}
				this.$emit('selectHyfl', {
					list,
					listName
				})
				this.show = false
			},
			selectAll(idx) {
				if (this.hyList[idx].check) {
					this.hyList[idx].check = false
				} else {
					this.hyList[idx].check = true
				}
				for (let i = 0; i < this.hyList[idx].data.length; i++) {
					this.hyList[idx].data[i].check = this.hyList[idx].check
				}
				this.$forceUpdate()
			},
			testAll(idx) {
				let flag = true
				for (let i = 0; i < this.hyList[idx].data.length; i++) {
					if (!this.hyList[idx].data[i].check) {
						flag = false
					}
				}
				this.hyList[idx].check = flag
			},
			selectType(idx, idxx) {
				if (this.hyList[idx].data[idxx].check) {
					this.hyList[idx].data[idxx].check = false
				} else {
					this.hyList[idx].data[idxx].check = true
				}
				this.$forceUpdate()
				this.testAll(idx)
			},
			openModal(type) {
				this.show = true
				this.$api.company.getHylbList({
					type: this.type
				}).then(res => {
					this.hyList = res.data
					if (type === 'mine') {
						this.$api.member.getMemberInfo().then(res => {
							if (res.data.member.hyfl) {
								let hyfl = res.data.member.hyfl.split(',')
								console.log('hyfl', hyfl);
								for (let iii = 0; iii < hyfl.length; iii++) {
									for (let i = 0; i < this.hyList.length; i++) {
										for (let ii = 0; ii < this.hyList[i].data.length; ii++) {
											if (this.hyList[i].data[ii].id == hyfl[iii]) {
												this.hyList[i].data[ii].check = true
											}
										}
									}
								}
							}
							this.$forceUpdate()
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
		.big-title {
			font-weight: bold;
			font-size: 40rpx;
			line-height: 56rpx;
		}

		.mid-title {
			font-weight: bold;
			font-size: 28rpx;

		}
	.page2 {
		width: 100%;

		.btm-title {
			margin-bottom: 66rpx;
		}

		.select-wrap {
			margin-bottom: 42rpx;

			.select-label {
				font-weight: bold;
				font-size: 32rpx;
				margin-bottom: 24rpx;
			}

			.select-list {
				overflow: hidden;
				width: 100%;

				.select-option {
					width: auto;
					height: 60rpx;
					border-radius: 36rpx;
					border: 1px solid #D9D9D9;
					padding: 0 20rpx;
					margin-right: 20rpx;
					margin-bottom: 22rpx;
					float: left;
					line-height: 58rpx;

					&.active {
						background: #EC2424;
						border: 1px solid #EC2424;
						color: #FFFFFF;
					}
				}
			}
		}
	}
</style>